﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{
}

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" lay-filter="notice-form" style="padding: 15px 0 0 0;">
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="PublicUserId" value="0"/>
               
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="Title" lay-verify="required" placeholder="请输入标题"
                           autocomplete="off" class="layui-input" value="@Model.Title" maxlength="50" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">类型</label>
                    <div class="layui-input-block" >
                        <select name="NoticType" lay-verify="required">
                            <option value="0" @(Model.NoticType == 0 ? "selected" : "")>通知</option>
                            <option value="1" @(Model.NoticType == 1 ? "selected" : "")>公告</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label ">内容</label>
                    <div class="layui-input-block">
                        <textarea name="Content" id="Content" placeholder="请输入内容" class="layui-textarea" maxlength="500">@Model.Content</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label layui-form-required">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" id="PublicTime" name="PublicTime" lay-verify="required" placeholder="请输入发布时间"
                               autocomplete="off" class="layui-input" value="@(Model.PublicTime==null?"":Model.PublicTime.ToString("yyyy-MM-dd"))" maxlength="50" />
                        </div>
                    </div>
                    <div class="layui-inline">
                         <label class="layui-form-label layui-form-required">状态</label>
                        <div class="layui-input-block">
                            <select name="Status">
                                <option value="">全部</option>
                                <option value="1" @(Model.Status == 1 ? "selected" : "")>发布</option>
                                <option value="0" @(Model.Status == 0 ? "selected" : "")>草稿</option>
                            </select>
                        </div>
                    </div>
                    
                </div>
                <div class="layui-form-item">
                     <div class="layui-input-block">
                         <blockquote class="layui-elem-quote">如果状态是草稿不用选择人员</blockquote>
                    <div id="userlist" class="user-transfer"></div>
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        
                        <button class="layui-btn layui-hide" lay-submit lay-filter="notice-submit" id="notice-submit">提交</button>
                    </div>
                </div>
        </form>
    </div>
    </div>

@section scripts{

       <script type="text/javascript">
        layui.use(['lscom', 'form', 'element','transfer', 'laydate','tinymce'], function () {
            var $ = layui.$;
            var lscom = layui.lscom;
            var form = layui.form;
            var element = layui.element;
            var transfer = layui.transfer;
            var laydate = layui.laydate;
            var tinymce = layui.tinymce;
            var index = parent.layer.getFrameIndex(window.name);
            //parent.layer.iframeAuto(index);
         
            transfer.render({
                elem: '#userlist'
                ,id:'userdata'
                , data: @Html.Raw( ViewBag.UserTransfer)
                , title: ['人员列表', '已选人员']
                , showSearch: true
                ,width: 300 //定义宽度
                ,height: 200 //定义高度
            })

            //开始日期
            laydate.render({
                elem: '#PublicTime'
                ,type: 'date'
            });

            var edit = tinymce.render({
                elem: "#Content",
                menubar: false , 
                plugins: 'print preview searchreplace autolink fullscreen image link media code codesample table charmap hr pagebreak nonbreaking anchor advlist lists textpattern help emoticons autosave indent2em axupimgs kityformula-editor' , 
                toolbar: 'code undo redo restoredraft | cut copy | forecolor backcolor bold italic underline strikethrough link | alignleft aligncenter alignright alignjustify | bullist numlist blockquote subscript superscript removeformat | \
                    formatselect fontselect fontsizeselect | \
                    table image media charmap emoticons hr pagebreak print preview | fullscreen | indent2em lineheight axupimgs kityformula-editor' , 
                autosave_ask_before_unload: false ,
                font_formats: '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats;' ,

                images_upload_url: '/Upload/UploadTinymceFile?category=tf',
                images_upload_base_path: '/',
                paste_data_images: false,
                file_picker_types: 'file media',
                height: 550,
                //自定义文件选择器的回调内容 此方法只有在点击上方图片按钮才会触发 
                file_picker_callback: function (callback, value, meta) {
                    if (meta.filetype === 'media') {
                        // 动态创建上传input，并进行模拟点击上传操作，达到本地上传视频效果。 
                        let input = document.createElement('input');
                        //创建一个隐藏的
                        input.setAttribute('type', 'file');
                        input.setAttribute("accept", ".mp4");
                        //let that = this;
                        input.onchange = function () {
                            let file = this.files[0];
                            let formData = new FormData();
                            formData.append("file", file);
                            formData.append("category", "tf");
                            var waitIndex = parent.layer.load(2);
                            lscom.ajax({
                                url: "/Upload/UploadFile",
                                data: formData,
                                lsHandleError: false,
                                processData: false,
                                contentType: false,
                            }).done(function (data) {
                                if (data.code == 0) {
                                    callback(data.data.url);
                                }
                            }).fail(function (message) {
                                parent.layer.msg(message, { icon: 5 });
                            }).always(function () {
                               parent.layer.close(waitIndex);
                            });
                        }
                        //触发点击 
                        input.click();
                    }
                     if (meta.filetype === 'file') {
                          // 动态创建上传input，并进行模拟点击上传操作，达到本地上传视频效果。 
                        let input = document.createElement('input');
                        //创建一个隐藏的
                        input.setAttribute('type', 'file');
                        input.setAttribute("accept", ".pdf");
                        //let that = this;
                        input.onchange = function () {
                            let file = this.files[0];
                            let formData = new FormData();
                            formData.append("file", file);
                            formData.append("category", "tf");
                            var waitIndex = parent.layer.load(2);
                            lscom.ajax({
                                url: "/Upload/UploadFile",
                                data: formData,
                                lsHandleError: false,
                                processData: false,
                                contentType: false,
                            }).done(function (data) {
                                if (data.code == 0) {
                                    callback(data.data.url);
                                }
                            }).fail(function (message) {
                                parent.layer.msg(message, { icon: 5 });
                            }).always(function () {
                               parent.layer.close(waitIndex);
                            });
                        }
                        //触发点击 
                        input.click();
                     }
                },
                images_upload_handler: function (blobInfo, succFun, failFun) {
                    var xhr, formData;
                    var file = blobInfo.blob();//转化为易于理解的file对象
                   
                    formData = new FormData();
                    formData.append('file', file, file.name);
                    formData.append("category", "tf");
                   
                    var waitIndex = parent.layer.load(2);
                    lscom.ajax({
                        url: "/Upload/UploadFile",
                        data: formData,
                        lsHandleError: false,
                        processData: false,
                        contentType: false,
                    }).done(function (data) {
                        if (data.code == 0) {
                            if (data.data != null && data.data.url != "") {
                                succFun(data.data.url);
                            }
                        }
                    }).fail(function (message) {
                        parent.layer.msg(message, { icon: 5 });
                    }).always(function () {
                        parent.layer.close(waitIndex);
                    });
                }
            });
            window.submitForm = function (status) {
                $("#notice-submit").click();
            }

            form.on('submit(notice-submit)', function (data) {
                var getUserData = transfer.getData('userdata');
                if (getUserData.length == 0 && data.field.Status=="1") {
                      parent.layer.msg("请选择人员", { icon: 5 });
                      return false;
                }
                var userid=[];
                for (var i = 0; i < getUserData.length;i++) {
                    userid.push(getUserData[i].value);
                }
                data.field.Content = edit.getContent();
                data.field.UserList = userid;
                var field = data.field;
                var waitIndex = parent.layer.load(2);
                lscom.ajax({
                    url: "/Systems/Notice/SaveNotice",
                    data: JSON.stringify(field),
                    lsHandleError: false
                }).done(function (data) {
                    if (data.code == 0) {
                        data.index = index;
                        let parentWindow = parent.selectedWindow().window;
                        parentWindow.saveCallback(data);
                    }
                }).fail(function (message) {
                    lscom.notify.error(message);
                }).always(function () {
                    parent.layer.close(waitIndex);
                });

                return false;
            });
        });
    </script>

   
}
